package demo1;
class Shape{
    public void draw(){
        System.out.println("画图形");
    }
}
class Rect extends Shape{
    @Override
    public void draw() {
        System.out.println("矩形");
    }
}
class Cycle extends Shape{
    @Override
    public void draw() {
        System.out.println("圆");
    }
}
class Flower extends Shape{
    @Override
    public void draw() {
        System.out.println("花");
    }
}
public class Test {
    public static void drawMap(Shape shape) {
        shape.draw();//
    }
   /* public static void drawMaps(){
        Cycle cycle = new Cycle();
        Rect rect = new Rect();
        Flower flower = new Flower();
        String[] shapes ={"cycle","rect","cycle","rect","flower"};
        for(String shape:shapes){
            if(shape.equals("cysle")){
                cycle.draw();
            }else if(shape.equals("rect")){
                rect.draw();
            }else if(shape.equals("flower")){
                flower.draw();
            }
        }
    }*/
    //多态实现上述代码
    public static void drawMaps() {
        Cycle cycle = new Cycle();
        Rect rect = new Rect();
        Flower flower = new Flower();
        //这里实现向上转型
       /* Shape[] shapes = {new Cycle(),new Rect(),new Cycle(),new Rect()
        ,new Flower()};*/
        Shape[] shapes = {cycle,rect,cycle,rect,flower};
        for(Shape shape:shapes){
            shape.draw();
        }
    }
    public static void main(String[] args) {
        Cycle cycle = new Cycle();
        Rect rect = new Rect();
        Flower flower = new Flower();

        drawMap(cycle);
        drawMap(rect);
        drawMap(flower);


    }
}
